<%@page import="my.db.DTO.ArticleTypeDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="my.db.DTO.ArticleDTO"%>
<%@ include file="sites/ad_header.jsp" %>
<%
	if(session.getAttribute("user") ==null){
		response.sendRedirect("LoadIndex.jsp");
	}
%>
<%
	ArticleDTO ar=(ArticleDTO)request.getAttribute("readArticle");
	ArrayList<ArticleTypeDTO> lst_atdto=(ArrayList<ArticleTypeDTO>)request.getAttribute("ArticleTypeEdit");
	if(ar !=null || lst_atdto !=null){
					%>
<div class="r-body">
	<div class="page-title">
		<p>Edit Article Information</p>
	</div>
	<div class="frm-action">
					<form action="./update_article.article?id=<%=ar.getArticleNo()%>" method="post" >			
					<table border="0" cellpadding="10">
					<!-- articleNo, articleTitle, 
						articleContent, userID, articleTypeID,
					 -->
					 	<tr>
					 		<td width="150"> <a href="javascript:history.go(-1);"><img src="Image/go_back.png" class="go_back" title="Back to Main page"/> </td>
					 		<td colspan="3"></td>
					 	</tr>
						<tr>
							<td>Article No</td>
							<td><input type="text" name="articleNo" class="articleNo" value="<%=ar.getArticleNo()%>" readonly="readonly"/></td>							
						</tr>
						<tr>
							<td>Article Title</td>
							<td><input type="text" required="required" name="articleTitle" class="articleTitle" value="<%=ar.getArticleTitle()%>"/></td>						
						</tr>
						<tr>
							<td>Article Type</td>
							<td>
								<select name="articleTypeID" class="articleTypeID">
									<%
										for(int i=0;i<lst_atdto.size();i++){
											ArticleTypeDTO adto=lst_atdto.get(i);	
											if(adto.getTypeID()==ar.getArticleType().getTypeID()){
												System.out.println(adto.getTypeID());
									%>			
												<option value=<%=adto.getTypeID()%> selected>
													<%=adto.getTypeName()%>
												</option>
									<%	}
											else{
									%>
										<option value=<%=adto.getTypeID()%>>
											<%=adto.getTypeName()%>
										</option>
									<%
										}
									}
									
									%>
									
								</select>
							</td>
						
						</tr>
						<tr>
							<td colspan="2">
							<textarea rows="20" required="required" cols="80" name="articleContent" class="articleContent" id="articleContent"><%=ar.getArticleContent()%></textarea>
							</td>
						</tr>
						<tr>

							<td></td>
							<td><input type="submit" value="UPDATE" class="btn-default" style="float:right;"/></td>
						</tr>
					</table>
					</form>
	<%} %>
	<script type="text/javascript">
		$(function(){
			CKEDITOR.replace("articleContent");
		});
	</script>
	
</div><!-- End r-body -->